package com.flower.controller;

import com.flower.model.entity.SysDict;
import com.flower.model.entity.SysMenu;
import com.flower.model.vo.MenuVo;
import com.flower.result.Result;
import com.flower.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName MenuController
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/12 10:44
 *@Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/menu")
@Api(tags = "菜单管理")
public class MenuController {
    @Autowired
    private MenuService  menuService;

    @GetMapping
    @ApiOperation("获取菜单")
    public Result<List> getMenu(String name){
        log.info("获取菜单：{}",name);
        List<MenuVo> menuVo =menuService.getAllMenu(name);
        return Result.success(menuVo);
    }

    @GetMapping("/icons")
    @ApiOperation("获取图标")
    public Result<List> getIcons(){
        log.info("获取图标");
        List<SysDict> icons = menuService.getIcons();
        return Result.success(icons);
    }

    @PostMapping
    @ApiOperation("新增菜单/修改菜单")
    public Result update(@RequestBody SysMenu sysMenu){
        log.info("修改菜单：{}",sysMenu);
        menuService.updateMenu(sysMenu);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除菜单")
    public Result delete(@PathVariable Integer id){
        log.info("删除菜单：{}",id);
        menuService.deleteMenu(id);
        return Result.success();
    }
    @PostMapping("/del/batch")
    @ApiOperation("批量删除菜单")
    public Result deleteList(@RequestBody List<Integer> ids){
        log.info("批量删除菜单：{}",ids);
        menuService.deleteMenuList(ids);
        return Result.success();
    }
    @GetMapping("ids")
    @ApiOperation("获取菜单已分配接口")
    public Result<List<Integer>> getMenuIds(Integer roleId){
        log.info("获取菜单已分配接口：{}",roleId);
        List<Integer> menuIds = menuService.getRoleMenu(roleId);
        return Result.success(menuIds);
    }
}
